<?php
class Core_Model_DbTable_Purposes extends Zend_Db_Table_Abstract {
    protected $_name = 'purposes';
    
    public function getAll($cols = NULL) {
        $select = $this->select();
        if (isset($cols)) {
            $select->from($this->_name, $cols);
        } else {
            $select->from($this->_name);
        }
        return $this->fetchAll($select);
    }
    
    public function getMultiOptions() {
        $ports = $this->getAll(array("id", "name"));
        $result = array();
        foreach ($ports as $port) {
            $result[][$port->id] = $port->name;
        }
        return $result;
    }
    
    public function batchDelete($ids) {
        $cond = $this->getAdapter()->quoteInto("id in (?)", $ids);
        return $this->delete($cond);
    }
    
    public function getPurposeDetail($pid) {
        return $this->fetchRow($this->getAdapter()->quoteInto("id = (?)", $pid));
    }

    public function get($id) {
        return $this->fetchRow("id = $id");
    }
    
    public function getMulti($ids) {
        if ( !empty($ids) ) {
            $cond = $this->getAdapter()->quoteInto("id IN (?)", $ids);
            $purposes = $this->fetchAll($cond)->toArray();
            $result = array();
            foreach ($purposes as $purpose) {
                $result[$purpose['id']] = $purpose;
            }
            return $result;
        } 
        return array();
    }
}
?>
